'''
This file is part of DopplerShift.

    DopplerShift is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    DopplerShift is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DopplerShift.  If not, see <http://www.gnu.org/licenses/>.
'''
from dopplershift.core.patterns.mapping import DSMapObject, MappingError
from dopplershift.core.exc import DSException
from dopplershift.core.containers.mediator import getMediator

class UnknownBackendType(DSException):
    '''
    Raise if try using unknown backends type
    '''
class IncompotibleRequest(DSException):
    '''
    Raising exception if backend get incompatible class fetching request
    '''
class BaseBackendRequest(DSMapObject):
    '''
    Simple containing class for make simple container and make custom objects
    for equialenting backend interfaces
    '''
    def _setItem(self, attr_key, attr_value):
        if hasattr(self, attr_key):
            DSMapObject._setItem(self, attr_key, attr_value)
        else:
            raise MappingError('attribute %s not defing in class prototype'%(attr_value))
        

class BaseBackend:
    '''
    Abstract class, for definition interfaces dopplershift.collector backend
    '''
    req_type = None
    def fetch(self, request, callback=None):
        '''
        processing custom loging and return information object to setting callback 
        '''
        if not isinstance(request, self.req_type):
            raise IncompotibleRequest('Incompotible request type')
    def _fetch(self, request, callback=None):
        '''
        Override this method, if you need realising detailed backend, or user backend known
        as default for interesing subsystem
        '''